﻿<div id="formLogin">
    @Html.Action("LogonPartial", "Account")
</div>
<script type="text/javascript">
    $(function () {
        $("#formDadosLogin").submit(function (e) {
            e.preventDefault();
            $.post($(this).attr("action"), $(this).serialize(), function (retorno) {
                if (retorno.logged) {
                    $("#formDadosLogin")[0].reset();

                    $("#labelErroLogin").hide();
                    $('#formLogin').slideUp('slow');
                    $("#botaoLogin").html(retorno.usuario);
                }
                else {
                    $("#labelErroLogin").show();
                    $("#labelErroLogin").html(retorno.mensagem);
                }
            });
        });
    });

    function botaoLogin() {
        if (!isDisplayed($("#formLogin"))) {
            $('#formLogin').slideDown('slow');
        } else {
            if (IsMyFormValid())
                $('form#formDadosLogin').submit();
        }
    }

    function IsMyFormValid() {
        var isValid = false;

        isValid = $('#formDadosLogin').validate().element($('#UserName'));
        isValid = ($('#formDadosLogin').validate().element($('#Password'))) ? isValid : false;

        return isValid;
    }
</script>
@if (Request.IsAuthenticated)
{
    <a href="#">@User.Identity.Name</a>
    <span>/</span>
    @Html.ActionLink(PortalCurriculo.MvcWebUI.Resources.Shared.Layout.Logoff, "LogOff", "Account", new { @class = "textBemVindo" })
}
else
{
@*@Html.ActionLink(PortalCurriculo.MvcWebUI.Resources.Shared.Layout.Login, "LogOn", "Account")*@
    <a href="#" id="botaoLogin" onclick="botaoLogin();">@PortalCurriculo.MvcWebUI.Resources.Shared.Layout.Login</a>
    <span>/</span>
    @Html.ActionLink(PortalCurriculo.MvcWebUI.Resources.Shared.Layout.CadastreSe, "SelecionarTipoUsuario", "Usuario")
}
